// 卡延期卡信息查询
var currentCardNo;
function do_query_activeCardInfo(cardNo) {
	if (!$isNull(cardNo)) {
		currentCardNo = cardNo;
		resetValue();
		$.ajax({
			type : "POST",
			url : basePath + 'cardHolderUserServlet.do?method=ActiviteCardInfo',
			cache : false,
			data : '&cardNo=' + cardNo,
			success : function(data) {
				if (data == 'false') {
					$('#returnString').html("此卡不存在!");
					return;
				} else {
					$(window).trigger("EV_fancyOpen", "CardExtendExpired");
					$('#CardExtendExpired').show();
					$('#returnString').html("");
					data = $.parseJSON(data);
					var cardClassicName = data.cardClassicName;
					var balance = data.balance;
					var expired = data.expired;
					$('#ceeCardNo').html(currentCardNo);
					if (!$isNull(balance))
						$('#balance').html(balance + "元");
					if (!$isNull(expired))
						$E('expired').value = expired.substr(0, 11);
					if (!$isNull(cardClassicName))
						$('#cardClassicName').html(cardClassicName);
					$('#CardExtendExpired').show();
				}
			}
		});
	} else {
		$('#CardExtendExpired').hide();
	}
}

// 卡延期操作
function do_CardExtendExpired(isTrail) {
	var cardNo = currentCardNo;
	var expired = $V('expired');
	var remark = $V('remark');
	if (!$isNull(cardNo)) {
		$.ajax({
					type : "POST",
					url : basePath
							+ 'cardHolderUserServlet.do?method=CardExtendExpired',
					cache : false,
					data : {
						cardNo : cardNo,
						expired : expired,
						isTrail : isTrail,
						remark : encodeURI(remark)
					},
					success : function(data) {
						if (data == 'false') {
							$('#returnString').html("此卡不存在!");
							$(window).trigger("EV_fancyClose",
									"CardExtendExpired");
							return;
						} else if (data.indexOf('error:') > -1) {
							alert(data.replace("error:", ""));
						} else {
							$('#returnString').empty();
							data = $.parseJSON(data);
							if (false == isTrail) {
								alert("延期成功!");
								$(window).trigger("EV_fancyClose");
							}
							$E('expired').value = data.strExpired.substr(0, 11);
							if (!$isNull(data.fee))
								$('#ceeFee').html($formatAmt(data.fee) + "元");
							else
								$('#ceeFee').html("0 元");
						}
					}
				});
	}
}
// 重置卡延期中相关值
function resetValue() {
	$E('remark').value = "";
	$('#balance').html("");
	$E('expired').value = "";
	$('#ceeFee').html("");
	$('#cardClassicName').html("");
}
// ///////////////////////////////卡延期结束
/**
 * 卡种类变更
 * 
 * @param {}
 *            cardNo
 */
function cardClassicChange_Info(cardNo) {
	if (!$isNull(cardNo)) {
		currentCardNo = cardNo;
		$.ajax({
			type : "POST",
			url : basePath + 'cardHolderUserServlet.do?method=ActiviteCardInfo',
			cache : false,
			data : '&cardNo=' + cardNo,
			success : function(data) {
				if (data == 'false') {
					$('#returnString').html("此卡不存在!");
					$(window).trigger("EV_cardNoExist", '#CardClassicChange');
					$('#cardchange_btn').hide();
					return;
				} else {
					$('#CardClassicChange').show();
					$("#toCardClassicId").empty();
					$E("password").value = "";
					$('#cccFee').empty();
					$("#ccRemark").empty();
					$('#returnString').html("");
					$('#pay').html("");
					data = $.parseJSON(data);
					var ownerName = data.ownerName;
					var balance = data.balance;
					var fromCardClassicName = data.cardClassicName;
					var fromCardClassicId = data.cardClassicId;
					$.ajax({
						type : "POST",
						url : basePath
								+ '/cardHolderUserServlet.do?method=GetCardClassicChangeList',
						cache : false,
						data : '&fromCardClassicId=' + fromCardClassicId,
						success : function(data) {
							data = $.parseJSON(data);
							$("#toCardClassicId")
									.append("<option value='-1'>-----请选择-----</option>");
							for (var i = 0; i < data.length; i++) {
								$("#toCardClassicId").append("<option value='"
										+ data[i].toClassicId + "'>"
										+ data[i].toClassicName + "</option>");
							}
						}
					});
					$('#cccCardNo').html(currentCardNo);
					if (!$isNull(balance))
						$('#oldBalance').html(balance + "元");
					if (!$isNull(fromCardClassicName))
						$('#fromCardClassicName').html(fromCardClassicName);
					if (!$isNull(fromCardClassicId))
						$E('fromCardClassicId').value = fromCardClassicId;
					$('#cardchange_btn').show();
					$(window).trigger("EV_fancyOpen", "CardClassicChange");
				}
			}
		});
	}
}
/**
 * 卡种类变更操作
 * 
 * @param {}
 *            isTrail
 */
function doCardClassicChange(isTrail) {
	$.ajax({
		url : basePath + '/cardHolderUserServlet.do?method=DoCardClassicChange',
		type : "POST",
		cache : false,
		data : {
			cardNo : currentCardNo,
			toCardClassicId : $E("toCardClassicId").value,
			password : $E("password").value,
			remark : $E("ccRemark").value,
			isTrail : isTrail
		},
		success : function(data) {
			if (data.indexOf('error') > -1) {
				alert(data.replace("error:", ""));
			} else {
				$('#returnString').empty();
				data = $.parseJSON(data);
				if (false == isTrail) {
					alert("变更卡种类成功!");
					$(window).trigger("EV_fancyClose");
				}
				$('#cccFee').html($formatAmt(data.fee) + " 元");
				$('#cardchange_resultinfo').show();
				$('#cardchange_btn').hide();
			}
		}
	});
}
/**
 * 显示余额
 * 
 * @param {}
 *            divNo divId
 * @param {}
 *            cardNo 卡号
 */
function showBalance(divNo, cardNo) {
	$.ajax({
				url : basePath
						+ '/cardHolderUserServlet.do?method=GetCardBalance',
				type : "POST",
				cache : false,
				data : {
					cardNo : cardNo
				},
				success : function(data) {
					if (data.indexOf('error') > -1) {
						$('#' + divNo).css({
									display : "none"
								});
						$('#returnString').html("此卡不存在!");
					} else {
						$('#returnString').empty();
						$('#' + divNo).css({
									display : "",
									float : "right"
								});
						if ('0' == data) {
							$('#' + divNo).html("余额：0 元");
						} else {
							$('#' + divNo).html("余额：" + $formatAmt(data) + "元");
						}
					}
				}
			});
}
/**
 * 卡改密
 */
function ChangeCardPassword(cardNo) {
	currentCardNo = cardNo;
	$(window).trigger("EV_fancyOpen", "ChangeCardPasswordDiv");
	$('#ccpCardNo').html(currentCardNo);
	$E('oldCardPwd').value = "";
	$E('newCardPwd').value = "";
	$E('newCardPwd2').value = "";
	$E('ccpRemark').value = "";
}
/**
 * 处理卡改密
 */
function do_ChangeCardPassword() {
	if ($isNull($V('oldCardPwd'))) {
		alert("旧密码不能为空");
		return;
	}
	if ($isNull($V('newCardPwd'))) {
		alert("新密码不能为空");
		return;
	}
	if ($isNull($V('newCardPwd2'))) {
		alert("请再次输入新密码");
		return;
	}
	$.ajax({
				url : basePath
						+ '/cardHolderUserServlet.do?method=ChangeCardPassword',
				type : "POST",
				cache : false,
				data : {
					cardNo : currentCardNo,
					oldCardPwd : $V('oldCardPwd'),
					newCardPwd : $V('newCardPwd'),
					ccpRemark : $V('ccpRemark')
				},
				success : function(data) {
					if ('true' == data) {
						alert("卡密码修改成功!");
						$(window).trigger("EV_fancyClose");
					} else {
						alert(data);
					}
				}
			});
}
/**
 * 取消卡关联
 */
function cancelCardHolderUserLink(cardNo) {
	if (confirm("确认取消关联卡号为 [" + cardNo + "] 的卡吗")) {
		if (confirm("请再次确认取消关联")) {
			window.location.href = basePath
					+ "cardHolderUserServlet.do?method=CancelCardHoldUserLink&cardNo="
					+ cardNo;
		}
	}
}
/**
 * 添加关联卡
 */
function addCardHoldUserLink() {
	var cardNo = $V('addchulinkCardNo');
	var cardPwd = $V('addchulinkPwd');
	if ($isNull(cardNo)) {
		alert("卡号不能为空");
		return;
	}
	if ($isNull(cardPwd)) {
		alert("卡密码不能为空");
		return;
	}
	window.location.href = basePath
			+ "cardHolderUserServlet.do?method=AddCardHoldUserLink&cardNo="
			+ cardNo + "&cardPwd=" + cardPwd;
}
// 卡临时挂失
function CardTemporaryLoss(cardNo) {
	currentCardNo = cardNo;
	$('#ctlCardNo').html(cardNo);
	$E('ctlRemark').value = "";
}
// 卡临时挂失操作
function do_CardTemporaryLoss() {
	$.ajax({
				url : basePath
						+ '/cardHolderUserServlet.do?method=CardTemporaryLoss',
				type : "POST",
				cache : false,
				data : {
					cardNo : currentCardNo,
					remark : $V('ctlRemark')
				},
				success : function(data) {
					if ('true' == data) {
						alert("卡临时挂失成功!");
						$(window).trigger("EV_fancyClose");
					} else {
						alert(data);
					}
				}
			});
}